package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.mapper.EmployeeMapper;
import com.itheima.reggie.pojo.Employee;
import com.itheima.reggie.service.EmployeeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 员工管理
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {

    @Autowired
    EmployeeMapper employeeMapper;

    /**
     * 分页条件查询
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @Override
    public Page<Employee> selectPage(Integer page, Integer pageSize, String name) {
        //创建分页对象传入前端参数
        Page<Employee> empPage = new Page<>(page,pageSize);

        //模糊判断
        LambdaQueryWrapper<Employee> queryWrapper = Wrappers.lambdaQuery(Employee.class)
                .orderByDesc(Employee::getUpdateTime)
                .like(StringUtils.isNotBlank(name), Employee::getName, name);

        return employeeMapper.selectPage(empPage, queryWrapper);
    }
}
